import sys
import os
try:
    from main import import_database
except:
    import import_database

def main():
    target_dir = sys.argv[1]
    target_file = get_tif_file_path(target_dir)
    if target_file != "":
        import_database.import_geotiff(target_file)
    else:
        print("success")


def get_tif_file_path(target_dir):
    """
    在给定的目录中查找tif文件
    :param target_dir: 目标目录
    :return: 目录中tif文件的路径
    """
    result = ""
    for filename in os.listdir(target_dir):
        if filename.find(".tif") == len(filename) - 4:
            result = target_dir + '\\' + filename
    return result


def test():
    testPath = "D:\\tiff\\745511.tif"
    import_database.import_geotiff(testPath)


if __name__ == '__main__':
    main()
